package hotel.modal;

import hotel.dao.*;
import javafx.beans.property.*;

public class Room extends RoomType{
	private SimpleStringProperty roomNo;		// 房间编号
	private SimpleIntegerProperty status;		// 房间状态
	private SimpleStringProperty phoneNum;		// 房间电话
	private SimpleStringProperty position;		// 房间位置
	private SimpleIntegerProperty principal;	// 负责员工
	
	public Room(RoomDao rd) {
		super(rd.getRoomType());
		this.roomNo = new SimpleStringProperty(rd.getRoomNo());
		this.status = new SimpleIntegerProperty(rd.getStatus());
		this.phoneNum = new SimpleStringProperty(rd.getPhoneNum());
		this.position = new SimpleStringProperty(rd.getPosition());
		this.principal = new SimpleIntegerProperty(rd.getPrincipal());
	}
	
	public Object getDao() {
		RoomDao rd = new RoomDao();
		rd.setRoomNo(roomNo.get());
		rd.setStatus(status.get());
		rd.setPhoneNum(phoneNum.get());
		rd.setPosition(position.get());
		rd.setPrincipal(principal.get());
		rd.setTypeId(getTypeId());
		rd.setRoomType((RoomTypeDao)super.getDao());
		return rd;
	}
	
	public Room() {
		super();
		this.roomNo = new SimpleStringProperty("");
		this.status = new SimpleIntegerProperty(1);
		this.phoneNum = new SimpleStringProperty("");
		this.position = new SimpleStringProperty("");
		this.principal = new SimpleIntegerProperty(0);
	}
	
	public Room(Room roomInfo, int typeId, String typeName, int hourRoom, int bedNum, double deposit, double price) {
		super(typeId, typeName, hourRoom, bedNum, deposit, price);
		this.roomNo = new SimpleStringProperty(roomInfo.getRoomNo());
		this.status = new SimpleIntegerProperty(roomInfo.getStatus());
		this.phoneNum = new SimpleStringProperty(roomInfo.getPhoneNum());
		this.position = new SimpleStringProperty(roomInfo.getPosition());
		this.principal = new SimpleIntegerProperty(roomInfo.getPrincipal());
	}
	
	public Room(String roomNo, int status, String phoneNum, String position, int principal, 
			int typeId, String typeName, int hourRoom, int bedNum, double deposit, double price) {
		super(typeId, typeName, hourRoom, bedNum, deposit, price);
		this.roomNo = new SimpleStringProperty(roomNo);
		this.status = new SimpleIntegerProperty(status);
		this.phoneNum = new SimpleStringProperty(phoneNum);
		this.position = new SimpleStringProperty(position);
		this.principal = new SimpleIntegerProperty(principal);
	}
	
	public Room(String roomNo, int status, String phoneNum, String position, int principal, RoomType roomType) {
		super(roomType);
		this.roomNo = new SimpleStringProperty(roomNo);
		this.status = new SimpleIntegerProperty(status);
		this.phoneNum = new SimpleStringProperty(phoneNum);
		this.position = new SimpleStringProperty(position);
		this.principal = new SimpleIntegerProperty(principal);
	}
	
	public Room(Room roomInfo, RoomType roomType) {
		super(roomType);
		this.roomNo = new SimpleStringProperty(roomInfo.getRoomNo());
		this.status = new SimpleIntegerProperty(roomInfo.getStatus());
		this.phoneNum = new SimpleStringProperty(roomInfo.getPhoneNum());
		this.position = new SimpleStringProperty(roomInfo.getPosition());
		this.principal = new SimpleIntegerProperty(roomInfo.getPrincipal());
	}

	public final SimpleStringProperty roomNoProperty() {
		return this.roomNo;
	}
	
	public final String getRoomNo() {
		return this.roomNoProperty().get();
	}
	
	public final void setRoomNo(final String roomNo) {
		this.roomNoProperty().set(roomNo);
	}
	
	public final SimpleIntegerProperty statusProperty() {
		return this.status;
	}
	
	public final int getStatus() {
		return this.statusProperty().get();
	}
	
	public final void setStatus(final int status) {
		this.statusProperty().set(status);
	}
	
	public final SimpleStringProperty phoneNumProperty() {
		return this.phoneNum;
	}
	
	public final String getPhoneNum() {
		return this.phoneNumProperty().get();
	}
	
	public final void setPhoneNum(final String phoneNum) {
		this.phoneNumProperty().set(phoneNum);
	}
	
	public final SimpleStringProperty positionProperty() {
		return this.position;
	}
	
	public final String getPosition() {
		return this.positionProperty().get();
	}
	
	public final void setPosition(final String position) {
		this.positionProperty().set(position);
	}
	
	public final SimpleIntegerProperty principalProperty() {
		return this.principal;
	}
	
	public final int getPrincipal() {
		return this.principalProperty().get();
	}
	
	public final void setPrincipal(final int principal) {
		this.principalProperty().set(principal);
	}
	
	public String toString() {
		String str = String.format("RoomNo:%s Status:%s PhoneNum:%s Position:%s Principal:%d "+
				"TypeId:%d TypeName:%s HourRoom:%s BedNum:%d deposit:%.2f price:%.2f", 
				roomNo.get(), status.get(), phoneNum.get(), position.get(), principal.get(), 
				this.getTypeId(), this.getTypeName(), (this.isHourRoom()?"是":"否"),
				this.getBedNum(), this.getDeposit(), this.getPrice());
		return str;
		
	}
}
